import table from '@/components/dt/table/render.js'
import nameOpt from '@/biz/option/name.js'
import dateOpt from '@/biz/option/date.js'
import Opt from '@/components/dt/info/Opt.js'
import dt from '@dt/dt'

let _this = null

class Column extends Opt {
  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = []
    let houseArr = [
    {
      title: '户型名称',
      field: 'houseTypeName',
      minWidth: 120
    },
    {
      title: '格局',
      field: 'houseType',
      minWidth: 120,
      cell: {
        value: (row) => {
          return `${row.bedroom || '0'}室${
            row.hall || '0'
          }厅${row.toilet || '0'}卫`
        },
        text: {}
      }
    }, {
      title: '朝向',
      field: 'orientation',
      minWidth: 130,
      cell: {
        value: (row) => {
          return dt.dictInfo().__value('orientation', row.orientation)
        },
        text: {}
      }
    }, {
      title: '建面（㎡）',
      minWidth: 120,
      field: 'floorAreaScope',
      cell: {
        value: (row) => {
          return row.floorAreaScope || '待定'
        },
        text: {}
      }
    }, {
      title: '单价（元/㎡）',
      minWidth: 140,
      field: 'unitPriceScope',
      cell: {
        value: (row) => {
          return row.unitPriceScope || '待定'
        },
        text: {}
      }
    }, {
      title: '总价（万元）',
      minWidth: 120,
      field: 'totalPriceScope',
      cell: {
        value: (row) => {
          return row.totalPriceScope || '待定'
        },
        text: {}
      }
    }, {
      title: '销售状态',
      field: 'salesStatus',
      minWidth: 150,
      cell: {
        value: (row) => {
          return dt.dictInfo().__value('buSalesStatus', row.salesStatus)
        },
        text: {}
      }
    }]
    let carPort = [
    {
      title: '名称',
      field: 'houseTypeName',
      minWidth: 120
    },
    {
      title: '类型',
      field: 'carportType',
      minWidth: 120,
      cell: {
        value: (row) => {
          return dt.dictInfo().__value('stallType', row.carportType)
        },
        text: {}
      }
    }, {
      title: '是否配备充电桩',
      field: 'chargingPile',
      minWidth: 130,
      cell: {
        value: (row) => {
          return row.chargingPile ? row.chargingPile == 1 ? '配备' : '未配备' : '-'
        },
        text: {}
      }
    }, {
      title: '装修',
      minWidth: 140,
      field: 'decorationCarport',
      cell: {
        value: (row) => {
          return dt.dictInfo().__value('stallDecoration', row.decorationCarport)
        },
        text: {}
      }
    }, {
      title: '总价（万元）',
      minWidth: 120,
      field: 'totalPriceScope',
      cell: {
        value: (row) => {
          return row.totalPriceScope || '待定'
        },
        text: {}
      }
    }, {
      title: '建面（㎡）',
      minWidth: 120,
      field: 'floorAreaScope',
      cell: {
        value: (row) => {
          return row.floorAreaScope || '待定'
        },
        text: {}
      }
    }, {
      title: '销售状态',
      field: 'salesStatus',
      minWidth: 150,
      cell: {
        value: (row) => {
          return dt.dictInfo().__value('buSalesStatus', row.salesStatus)
        },
        text: {}
      }
    }]
    let shop = [
    {
      title: '名称',
      field: 'houseTypeName',
      minWidth: 120
    },
    {
      title: '开间（m）',
      minWidth: 120,
      field: 'facadeWidthScope',
    }, {
      title: '层高（m）',
      minWidth: 120,
      field: 'storyHeightScope',
    }, {
      title: '单价（元/㎡）',
      minWidth: 140,
      field: 'unitPriceScope',
      cell: {
        value: (row) => {
          return row.unitPriceScope || '待定'
        },
        text: {}
      }
    }, {
      title: '总价（万元）',
      minWidth: 120,
      field: 'totalPriceScope',
      cell: {
        value: (row) => {
          return row.totalPriceScope || '待定'
        },
        text: {}
      }
    }, {
      title: '建面（㎡）',
      minWidth: 120,
      field: 'floorAreaScope',
      cell: {
        value: (row) => {
          return row.floorAreaScope || '待定'
        },
        text: {}
      }
    }, {
      title: '销售状态',
      field: 'salesStatus',
      minWidth: 150,
      cell: {
        value: (row) => {
          return dt.dictInfo().__value('buSalesStatus', row.salesStatus)
        },
        text: {}
      }
    }]
    let office = [
    {
      title: '名称',
      field: 'houseTypeName',
      minWidth: 120
    },
    {
      title: '楼层',
      minWidth: 120,
      field: 'floor',
      cell: {
        value: (row) => {
          return dt.dictInfo().__value('floor', row.floor)
        },
        text: {}
      }
    }, {
      title: '装修',
      minWidth: 120,
      field: 'decoration',
      cell: {
        value: (row) => {
          return dt.dictInfo().__value('residenceDecoration', row.decoration)
        },
        text: {}
      }
    }, {
      title: '朝向',
      field: 'orientation',
      minWidth: 130,
      cell: {
        value: (row) => {
          return dt.dictInfo().__value('orientation', row.orientation)
        },
        text: {}
      }
    }, {
      title: '单价（元/㎡）',
      minWidth: 140,
      field: 'unitPriceScope',
      cell: {
        value: (row) => {
          return row.unitPriceScope || '待定'
        },
        text: {}
      }
    }, {
      title: '总价（万元）',
      minWidth: 120,
      field: 'totalPriceScope',
      cell: {
        value: (row) => {
          return row.totalPriceScope || '待定'
        },
        text: {}
      }
    }, {
      title: '建面（㎡）',
      minWidth: 120,
      field: 'floorAreaScope',
      cell: {
        value: (row) => {
          return row.floorAreaScope || '待定'
        },
        text: {}
      }
    }, {
      title: '销售状态',
      field: 'salesStatus',
      minWidth: 150,
      cell: {
        value: (row) => {
          return dt.dictInfo().__value('buSalesStatus', row.salesStatus)
        },
        text: {}
      }
    }]
    if (_this.curState == 'residence') {
      this.all = houseArr
    } else if (_this.curState == 'stall') {
      this.all = carPort
    } else if (_this.curState == 'shop') {
      this.all = shop
    } else if (_this.curState == 'office') {
      this.all = office
    }
    let handel = {
      title: '操作',
      fixed: 'right',
      width: 140,
      align: 'center',
      slots: {
        default: (params, h) => {
          let btns = []
          btns.push({
            title: '查看',
            event: 'toCheck',
            data: params.row
          })
          btns.push({
            title: _this.unlocking('0103030200') ? '编辑' : '',
            event: 'toEdit',
            data: params.row
          })
          btns.push({
            title: _this.unlocking('0103030300') ? '删除' : '',
            event: 'doDel',
            data: params.row
          })
          return table.cell.btns(_this, h, btns)
        }
      }
    }
    let handelRelateRoom = {
      title: '操作',
      fixed: 'right',
      width: 140,
      align: 'center',
      slots: {
        default: (params, h) => {
          let btns = []
          btns.push({
            title: '关联该户型',
            event: 'relateRoomHandel',
            data: params.row
          })
          return table.cell.btns(_this, h, btns)
        }
      }
    }
    if (_this.showHandel && !_this.path) {
      this.all.push(handel)
    } else if (_this.path && _this.path == 'relateRoom') {
      this.all.push(handelRelateRoom)
    }
  }

}

export default Column